package com.iqiju.guagua.photo.wx.mini.service;

import com.luhuiguo.fastdfs.domain.StorePath;
import com.luhuiguo.fastdfs.service.FastFileStorageClient;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class FastDFSService {

    @Value("${fdfs.http.path}")
    public String fdfsPath;

    @Autowired
    protected FastFileStorageClient storageClient;

    /** 新增（上传）文件 */
    public String upload(MultipartFile file) throws IOException {
        String fileType = FilenameUtils.getExtension(file.getOriginalFilename()).toLowerCase();
        StorePath path = storageClient.uploadFile(file.getInputStream(), file.getSize(), fileType, null);
        return fdfsPath + path.getFullPath();
    }

}
